{include file="public/header" /}
<link rel="stylesheet" href="/static/admin/addons/builder/css/base.css" media="all">
<style>
    .layui-form-item {
        margin-bottom: 15px !important;
        clear: both;
        *zoom: 1;
    }
</style>
<body>
<form action="{:url('user/recharge')}" class="layui-form v3-admin-form" id="form">
    <div class="layui-fluid layui-anim layui-anim-fadein">
        <div class="layui-card">
            <div class="layui-card-body" style="padding: 15px;">
                <div class="layui-row" style="padding-top: 8px">
                    <div class="layui-form-item">
                        <label class="layui-form-label">充值会员</label>
                        <div class="layui-input-block" lay-on="choose"
                             data-title="选择充值会员" data-url="{:url('user/choose')}" data-fun="chooseUser">
                            <input type="hidden" name="id" id="id" />
                            <input type="text" id="user" lay-verify="required" lay-reqtext="请选择充值会员"
                                   placeholder="点击选择充值会员" class="layui-input" readonly />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">充值账户</label>
                        <div class="layui-input-inline">
                            <select name="account" id="account" lay-filter="account" lay-verify="required" lay-reqtext="请选择要充值的账户">
                                <option value="">请选择</option>
                                {foreach name="assets" item="vo" }
                                <option value="{$key}">{$vo}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">账户余额</label>
                        <div class="layui-input-inline">
                            <input type="number" id="account_balance" placeholder="请选择要充值的账户" class="layui-input" disabled />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">充值方式</label>
                        <div class="layui-input-block">
                            <input type="radio" name="mode" value="1" title="增加" checked>
                            <input type="radio" name="mode" value="2" title="减少">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">充值金额</label>
                        <div class="layui-input-inline">
                            <input type="number" name="amount" lay-verify="required" lay-reqtext="请输入增加/减少的金额"
                                   placeholder="请输入增加/减少的金额" autocomplete="off" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">充值备注</label>
                        <div class="layui-input-block">
                            <input type="text" name="remarks" placeholder="充值备注(选填)"
                                   autocomplete="off" class="layui-input" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    {include file="public/submit" /}
</form>
</body>
{include file="public/footer" /}
<script type="text/javascript" src="/static/admin/js/choose.js"></script>
<script>
    $(function () {
        layui.use(['form'], function () {
            var form = layui.form, layer = layui.layer;
            form.on('select(account)', function (data) {
                var uid = $("#id").val();
                if (!uid) {
                    layer.msg('请先选择要充值的用户');
                    return false;
                }
                if (data.value) {
                    getBalance(uid, data.value)
                } else {
                    $('#account_balance').val('');
                }
            });
        });
    });
    function getBalance(uid, account) {
        if (uid && account) {
            $.ajax({
                type: 'GET',
                url: '{:url("user/checkBalance")}',
                data: {uid: uid, account: account},
                dataType: "json",
                success: function (data) {
                    if (data.code === 1) {
                        $('#account_balance').val(data.data);
                    } else {
                        layui.layer.msg(data.msg);
                    }
                }
            });
        }
    }
    function chooseUser(data) {
        $('#id').val(data.id);
        $("#user").val(data.code + ' - ' + data.nickname + ' - ' + data.mobile);
        getBalance(data.id, $("#account").val());
    }
</script>
</html>